﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;
using famails.common;

namespace famails.dao
{
    /// <summary>
    /// Summary description for baivietDAO
    /// </summary>
    public class baivietDAO
    {
        public baivietDAO()
        {
        }

        public DataTable GetalltblConfig()
        {
            SqlCommand cmd = new SqlCommand("select * from tblConfig ", ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter();
            DataTable table = new DataTable();
            da.Fill(table);
            cmd.Dispose();
            da.Dispose();
            return table;
        }
        public DataTable GetalltblConfig_id(string key)
        {
            SqlCommand cmd = new SqlCommand("select * from tblConfig where [key]=@key ", ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@key", SqlDbType.NVarChar).Value = key;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            da.Fill(table);
            cmd.Dispose();
            da.Dispose();
            return table;
        }
        public DataTable Getalltblconfig_idgroup(string idGroup)
        {
            SqlCommand cmd = new SqlCommand("select * from tblconfig where idGroup=@idGroup AND isShow='True'", ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@idGroup", SqlDbType.NVarChar).Value = idGroup;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            da.Fill(table);
            cmd.Dispose();
            da.Dispose();
            return table;
        }
        public DataTable Getallconfig()
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM V_baiviet",
                 ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }
        public DataTable Getbykey(string key)
        {
            SqlCommand cmd = new SqlCommand("SELECT * FROM V_baiviet WHERE [key] = @key",
                ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@key", SqlDbType.NVarChar).Value = key;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }

        public DataTable GetAllChild(string idGroup)
        {
            string sql = "SELECT * FROM tblConfig Where idGroup=@idGroup";
            SqlCommand cmd = new SqlCommand(sql, ConnectionData._MyConnection);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@idGroup", SqlDbType.NVarChar).Value = idGroup;
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable table = new DataTable();
            if (ConnectionData._MyConnection.State == ConnectionState.Closed)
            {
                ConnectionData._MyConnection.Open();
            }
            adapter.Fill(table);
            cmd.Dispose();
            adapter.Dispose();
            return table;
        }
    }
}